<?php slot('studyGroupsNav', 'active')?>
<div class="messages" id="wrapper">
	<?php include_partial('global/systemMessages')?>
	<div id="content">
	<!-- 
		<div id="location-bar">
			<form method="post" action="">
				<fieldset>
					<select>
						<option>Harvard</option>
					</select>
				</fieldset>
			</form>
			<ul class="breadcrumbs">
				<li class="first"><a href="#">Groups</a> &#xBB;</li>
				<li>Yale's English Peasants</li>
			</ul>
		</div>
	-->	
		<div id="main" style="padding-top: 30px;">
			<div class="main-heading">
				<h1><?php echo ($group ? $group->getName() : " " ) ?></h1>
			</div>
			<?php include_partial('groups/subnav', array('group_id' => $group_id, 'current' => 'Messages'))?>
			<div class="filter-links with-icon">
				<p>
					<?php echo link_to('Write a New Message &#xBB;', 'messages/new?group_id='.$group_id)?>					
				</p>
				<ul class="messages inline">
					<li>Messages</li>
				</ul>
			</div>
			<form action="<?php echo url_for('messages/update?group_id='.$group_id) ?>" method="post" id="messageForm" name="messageForm">
				<?php include_partial('messages/subnav', array('active' => $folder, 'group_id' => $group_id))?>
				<table cellspacing="0" cellpadding="0" id="inbox">
					<tbody>
						<tr>
							<th class="no-border"> </th>
							<th>Date</th>
							<th><?php echo $folder == MessagePeer::INBOX_FOLDER ? 'From' : 'To' ?></th>
							<th class="subject">
								<span>Subject</span>
							</th>
						</tr>
						<?php if($message_pager): ?>
							<?php foreach($message_pager->getResults() as $message): ?>
							<tr>
								<td class="centered">
									<input type="checkbox" name="messages[]" value="<?php echo $message->getId() ?>" />
								</td>
								<td class="date"><?php echo $message->getCreatedAt('%a %b %d, %Y %H:%m%p')?></td>
								<td>
									<?php if($folder == MessagePeer::INBOX_FOLDER): ?>
									<?php 
										echo link_to($message->getUserRelatedBySenderId()->getFullName(), 
										'user_profiles/show?id='.$message->getSenderId());
									?>
									<?php else: ?>
										<?php if($message->getType() == 'group'): ?>
											<?php echo $group->getName() ?>
										<?php else: ?>
										<?php 
											echo link_to(render_display_name($message->getUserRelatedByRecipientId()), 
											'user_profiles/show?id='.$message->getRecipientId());
										?>
										<?php endif ?>
									<?php endif ?>
								</td>
								<td class="subject">
									<?php 
										echo link_to(substr($message->getSubject(), 0, 40), 
										'messages/show?id='.$message->getId().'&group_id='.$group_id.'&folder='.$message->getFolder(),
										array('style' => 'font-weight: '. ($message->getSeen() ? 'normal;' : 'bold;') )
										); 
									?>
								</td>
							</tr>
							<?php endforeach ?>
						<?php endif ?>					
					</tbody>
				</table>
				<input type="hidden" name="group_id" value="<?php echo $group_id ?>" />
				<input type="hidden" name="folder" value="<?php echo $folder ?>" />
				<input type="hidden" name="is_ajax" value="true" />				
			</form>
		</div>
	</div>

</div>

<script type="text/javascript">

	$(document).ready(function() {
		$('#deleteMessage').click(function(){ 
			$('#messageForm').attr('action', $(this).attr('href'));	// copy over the url
			$(this).attr('href', 'javascript:void(0)');
			$('#messageForm').submit();
		});
		$('#markRead').click(function() { 
			$('#messageForm').attr('action', $(this).attr('href'));	// copy over the url
			$(this).attr('href', 'javascript:void(0)');
			$('#messageForm').submit(); 
		});
		$('#markUnread').click(function() { 
			$('#messageForm').attr('action', $(this).attr('href'));	// copy over the url
			$(this).attr('href', 'javascript:void(0)');
			$('#messageForm').submit(); 
		});
	});

	
</script>
